﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;

namespace HML
{
    /// <summary>
    /// 外观对象基类
    /// </summary>
    [TypeConverter(typeof(PropertyOrderConverter))]
    public abstract class AppearanceObjectBase
    {
        #region 字段

        /// <summary>
        /// 当前外观对象所属的主题对象
        /// </summary>
        protected ISkinObject owner = null;

        /// <summary>
        /// 当前外观对象的父外观对象
        /// </summary>
        protected AppearanceObjectBase parent = null;

        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="owner">当前外观对象所属的主题对象</param>
        /// <param name="parent">当前外观对象的父外观对象</param>
        public AppearanceObjectBase(ISkinObject owner, AppearanceObjectBase parent)
        {
            this.owner = owner;
            this.parent = parent;
        }

        #region 公开方法

        /// <summary>
        /// 刷新控件 （通过parent链找到所属owner的Invalidate）
        /// </summary>
        public virtual void Invalidate()
        {
            if (this.parent != null)
            {
                this.parent.Invalidate();
            }
            else if (this.owner != null)
            {
                this.owner.Invalidate();
            }
        }

        /// <summary>
        /// 重新布局内部元素并刷新控件 （通过parent链找到所属owner的InitializeInvalidate）
        /// </summary>
        public virtual void InitializeInvalidate()
        {
            if (this.parent != null)
            {
                this.parent.InitializeInvalidate();
            }
            else if (this.owner != null)
            {
                this.owner.InitializeInvalidate();
            }
        }

        #endregion

    }

}
